package yr.website

import grails.converters.JSON
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class MenuController {
    def menuService
    static final Logger logger = LoggerFactory.getLogger(MenuController.class)

    def getMenu() {
        def data = [:]
        def account = "${params.account ?: ''}"
        try {
            def manager = Manager.findByAccount(account)
            def roles = []
            def m = []
            roles = manager.rolesId.split(",")
            roles.each { roleId ->
                println roleId
                def role = Roles.findByRoleId(roleId)
                def pers = role.perId.split(",")
                pers.each { pid ->
                    def maps = menuService.ser(pid)
                    m.add(maps)
                }
            }
            data << [data: m]
            render data as JSON
        } catch (Exception e) {
            logger.error("MenuController -- getMenu Exception " + e.message)
        }
    }

    def getAll() {
        def data = [:]
        def list = []
        try {
            def lists = Menu.findAllByTypes("A")
            lists.each { menu ->
                def maps = menuService.ss(menu)
//                maps.put("label", menu.name)
                maps.put("value", menu.permissionId)
                maps.put("description", menu.description)
                list.add(maps)
            }
            data << [statuCode: "0", errMsg: "0", data: list]
            render data as JSON
        } catch (Exception e) {
            logger.error("MenuController -- getAll Exception " + e.message)
        }

    }

    def solutioncard() {
        render(view: "/solution_one_card")
    }

    def solutionmedical() {
        render(view: "/solution_medical")
    }

    def solutioncredit() {
        render(view: "/solution_credit")
    }

    def solutionlife() {
        render(view: "/solution_life")
    }

    def jiaxing() {
        render(view: "/jiaxing")
    }

    def jiangyin() {
        render(view: "/jiangyin")
    }

    def zhoushan() {
        render(view: "/zhoushan")
    }
}
